﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Twitter.Tests;
using System.ComponentModel.Design;
using FriendsNearby.Services;
using Twitter;
using Moq;
using FriendsNearby.Services.Entities;
using System.Linq.Expressions;


namespace FriendsNearbyBot.Tests
{
	[TestFixture]
	public class FriendsProcessorFixture : TestBase
	{
		Guid me = Guid.Empty;

		[Test]
		public void ICanListMyFriends()
		{

			// Warn: 
			var userService = new Mock<IUsersService>();
			var peopleNearbyServie = new Mock<IPeopleNearbyService>();

			userService.Expect(x => x.QueryUserRegistry(It.IsAny<Expression<Func<UserRegistry,bool>>>())).Returns(new UserRegistry { UserID = me });
			peopleNearbyServie.Expect(x => x.GetContacts(me, QueryContactsKind.Nearby)).Returns(
				new PersonNearby[]{ 
                    new PersonNearby { Relation = PersonNearbyRelation.Friend },
                    new PersonNearby { Relation = PersonNearbyRelation.Friend }
                });
			peopleNearbyServie.Expect(x => x.GetPeopleNearbySummary(me)).Returns(new PeopleNearbySummary(2, 1));

			MemoryBotClient bot = new MemoryBotClient("fnb");
			MemoryBotClient user = new MemoryBotClient("fnbtestb");
			bot.SetBuddy(user);
			user.SetBuddy(bot);

			var processor = new FriendsProcessor(userService.Object, peopleNearbyServie.Object, CreateMessageBuilder());

			processor.Process(bot, CreateMessage("friends", user.ScreenName, bot.ScreenName));

			//The message is splitted into 2 messages so the one I pick up is the last one.
			Message msg = user.Messages.GetAll().Last();
			string text = msg.Text;
			AssertString.StartsWith("2 friends nearby (nearest", msg.Text);
		}

		private IServiceProvider CreateServices()
		{
			return (new FriendsNearbySystem());
		}
	}
}

